package com.dragon.linkedlist;

/**
 * @author dragon
 * @version 1.0
 * @description
 * @date created in 2018-12-21
 */
public class LeetCodeLinkedListSolution3 {

    /**
     * 定义一个单链表
     */
    private static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    /**
     * 删除里面都为val的所有元素,返回链表头节点
     *
     * @param head
     * @param val
     * @return
     */
    public ListNode removeElements(ListNode head, int val) {
        if (head == null) {
            return null;
        }
        head.next = removeElements(head.next, val);
        if (head.val == val) {
            return head.next;
        } else {
            return head;
        }
    }
}
